<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="./vue.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        #app {
            width: 500px;
            margin: 50px auto;
            border: 3px solid red;
            padding: 2em;
        }

        .box {
            margin-top: 10px;
            border: 3px solid black;
            height: 200px;
            width: 200px;
            transition: all .5s;

        }

        .h100 {
            height: 100px;
        }

        .w100 {
            width: 100px;
        }

        .border10 {
            border: 10px solid #ccc;
        }
    </style>
</head>

<body>

    <div id="app">
        <h3 class="title">v-bind-绑定class</h3>
        <div>
            <button @click="hSwitch('h100')">切换高度</button>
            <button @click="hSwitch('w100')">切换宽度</button>
            <button @click="hSwitch('border10')">切换边框</button>
        </div>

        <!-- 如果对象中的属性值是true,
            则把对象中的属性名添加到类名中 -->
        <div class="box" :class="claObj">

        </div>
    </div>
    <script>
        // v-bind 是用来动态绑定元素的属性，而class也是元素的属性
        // 目标： 可以通过动绑定class来控制样式 。

        // 方式：绑定对象
        const vm = new Vue({
            el: "#app",
            data: {
                claObj: {
                    h100: true,
                    w100: true,
                    'border10': true
                }
            },
            methods: {
                hSwitch(className) {
                    this.claObj[className] = !this.claObj[className]
                }
            }
        })
    </script>
</body>
</html>